/*
 *  BoardManagement.c
 *  DamasIA
 *
 *  Created by Anderson on 10/06/12.
 *  Copyright 2012 __MyCompanyName__. All rights reserved.
 *
 */


//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>

#include "BoardManagement.h"
//#include "MovementEngine.h"




Board initBoard(){
	Board b;
	int i, j;
	char aux[8][8] = 
/*{
					 {'o',' ','o',' ','o',' ','o',' '}, //tabuleiro original
					 {' ','o',' ','o',' ','o',' ','o'}, 
					 {'o',' ','o',' ','o',' ','o',' '},
					 {' ',' ',' ',' ',' ',' ',' ',' '}, 
					 {' ',' ',' ',' ',' ',' ',' ',' '}, 
					 {' ','x',' ','x',' ','x',' ','x'},
					 {'x',' ','x',' ','x',' ','x',' '},
					 {' ','x',' ','x',' ','x',' ','x'}
					 };					 */
/*{
					 {'o',' ','o',' ','o',' ','o',' '}, //comer obrigatorio pecas pretas
					 {' ','o',' ','o',' ','o',' ','o'}, 
					 {'o',' ','o',' ','o',' ','o',' '},
					 {' ',' ',' ','x',' ',' ',' ',' '}, 
					 {' ',' ',' ',' ',' ',' ',' ',' '}, 
					 {' ','x',' ','x',' ','x',' ','x'},
					 {' ',' ',' ',' ',' ',' ',' ',' '},
					 {' ','x',' ','x',' ','x',' ','x'}
					 };*/
/*					 {{'o',' ','o',' ','o',' ','o',' '}, //come obrigatorio pecas brancas
					 {' ',' ',' ','o',' ',' ',' ','o'}, 
					 {'o',' ','o',' ','o',' ',' ',' '},
					 {' ',' ',' ',' ',' ',' ',' ',' '}, 
					 {' ',' ',' ',' ','o',' ',' ',' '}, 
					 {' ','x',' ','x',' ','x',' ','x'},
					 {'x',' ','x',' ','x',' ','x',' '},
					 {' ','x',' ','x',' ','x',' ','x'}
					 };					 
*/					 
/*
					 {'o',' ','o',' ','o',' ','o',' '}, //peca branca vira dama
					 {' ','o',' ','o',' ','o',' ','o'}, 
					 {'o',' ','o',' ','o',' ','o',' '},
					 {' ',' ',' ',' ',' ',' ',' ',' '}, 
					 {' ',' ',' ',' ',' ',' ',' ',' '}, 
					 {' ','x',' ','x',' ','o',' ','x'},
					 {'x',' ','x',' ','x',' ','x',' '},
					 {' ','x',' ',' ',' ','x',' ','x'}
					 };
*/

/*					 {{'o',' ','o',' ','o',' ',' ',' '}, //peca preta vira dama
					 {' ','o',' ','o',' ','o',' ','o'}, 
					 {'o',' ','o',' ','x',' ','o',' '},
					 {' ',' ',' ',' ',' ',' ',' ',' '}, 
					 {' ',' ',' ',' ',' ',' ',' ',' '}, 
					 {' ','x',' ','x',' ',' ',' ','x'},
					 {'x',' ','x',' ','x',' ','x',' '},
					 {' ','x',' ','x',' ','x',' ','x'}
					 };
*/
/*					 {{'o',' ','o',' ','o',' ','o',' '}, //testa se deixa setar origem com peca travada
					 {' ','o',' ','o',' ','o',' ','o'}, 
					 {'o',' ','o',' ','o',' ','o',' '},
					 {' ',' ',' ',' ',' ',' ',' ',' '}, 
					 {' ',' ',' ',' ','o',' ',' ',' '}, 
					 {' ','x',' ','x',' ','x',' ','x'},
					 {'x',' ','x',' ','x',' ','x',' '},
					 {' ','x',' ','x',' ','x',' ','x'}
					 };
*/
					 {{'O',' ','o',' ','o',' ','o',' '}, //teste se valida certo origem da dama
					 {' ','o',' ','o',' ','o',' ','o'}, 
					 {'o',' ','o',' ','o',' ','o',' '},
					 {' ',' ',' ',' ',' ',' ',' ',' '}, 
					 {' ',' ',' ',' ','O',' ',' ',' '}, 
					 {' ','x',' ',' ',' ','x',' ','x'},
					 {'x',' ','x',' ','x',' ','x',' '},
					 {' ','x',' ','x',' ','x',' ','x'}
					 };

	b.posValues[0][0] = 1; b.posValues[0][1] = 1; b.posValues[0][2] = 1; b.posValues[0][3] = 1; b.posValues[0][4] = 1; b.posValues[0][5] = 1; b.posValues[0][6] = 1; b.posValues[0][7] = 1;
	b.posValues[1][0] = 1; b.posValues[1][1] = 1; b.posValues[1][2] = 1; b.posValues[1][3] = 1; b.posValues[1][4] = 1; b.posValues[1][5] = 1; b.posValues[1][6] = 1; b.posValues[1][7] = 1;
	b.posValues[2][0] = 1; b.posValues[2][1] = 1; b.posValues[2][2] = 1; b.posValues[2][3] = 1; b.posValues[2][4] = 1; b.posValues[2][5] = 1; b.posValues[2][6] = 1; b.posValues[2][7] = 1;
	b.posValues[3][0] = 1; b.posValues[3][1] = 1; b.posValues[3][2] = 1; b.posValues[3][3] = 1; b.posValues[3][4] = 1; b.posValues[3][5] = 1; b.posValues[3][6] = 1; b.posValues[3][7] = 1;
	b.posValues[4][0] = 1; b.posValues[4][1] = 1; b.posValues[4][2] = 1; b.posValues[4][3] = 1; b.posValues[4][4] = 1; b.posValues[4][5] = 1; b.posValues[4][6] = 1; b.posValues[4][7] = 1;
	b.posValues[5][0] = 1; b.posValues[5][1] = 1; b.posValues[5][2] = 1; b.posValues[5][3] = 1; b.posValues[5][4] = 1; b.posValues[5][5] = 1; b.posValues[5][6] = 1; b.posValues[5][7] = 1;
	b.posValues[6][0] = 1; b.posValues[6][1] = 1; b.posValues[6][2] = 1; b.posValues[6][3] = 1; b.posValues[6][4] = 1; b.posValues[6][5] = 1; b.posValues[6][6] = 1; b.posValues[6][7] = 1;
	b.posValues[7][0] = 1; b.posValues[7][1] = 1; b.posValues[7][2] = 1; b.posValues[7][3] = 1; b.posValues[7][4] = 1; b.posValues[7][5] = 1; b.posValues[7][6] = 1; b.posValues[7][7] = 1;
	for (i = 0; i < 8; i++) {
		for (j = 0; j < 8; j++) {
			b.pieces[i][j] = aux[i][j];
		}
	}
	b.nWhite = 12;
	b.nBlack = 12;
	b.nWhiteQueen = 0;
	b.nBlackQueen = 0;
	b.whiteWeight = 12;
	b.blackWeight = 12;
	b.roundsToDraw = 15;
	return b;
}

void printBoard(Board b){
	printf("\n");
	printf("  +---+---+---+---+---+---+---+---+\n");
	printf("8 | %c | %c | %c | %c | %c | %c | %c | %c |\n", b.pieces[7][0], b.pieces[7][1], b.pieces[7][2], b.pieces[7][3], b.pieces[7][4], b.pieces[7][5], b.pieces[7][6], b.pieces[7][7]);
	printf("  +---+---+---+---+---+---+---+---+\n");
	printf("7 | %c | %c | %c | %c | %c | %c | %c | %c |\n", b.pieces[6][0], b.pieces[6][1], b.pieces[6][2], b.pieces[6][3], b.pieces[6][4], b.pieces[6][5], b.pieces[6][6], b.pieces[6][7]);
	printf("  +---+---+---+---+---+---+---+---+\n");
	printf("6 | %c | %c | %c | %c | %c | %c | %c | %c |\n", b.pieces[5][0], b.pieces[5][1], b.pieces[5][2], b.pieces[5][3], b.pieces[5][4], b.pieces[5][5], b.pieces[5][6], b.pieces[5][7]);
	printf("  +---+---+---+---+---+---+---+---+\n");
	printf("5 | %c | %c | %c | %c | %c | %c | %c | %c |\n", b.pieces[4][0], b.pieces[4][1], b.pieces[4][2], b.pieces[4][3], b.pieces[4][4], b.pieces[4][5], b.pieces[4][6], b.pieces[4][7]);
	printf("  +---+---+---+---+---+---+---+---+\n");
	printf("4 | %c | %c | %c | %c | %c | %c | %c | %c |\n", b.pieces[3][0], b.pieces[3][1], b.pieces[3][2], b.pieces[3][3], b.pieces[3][4], b.pieces[3][5], b.pieces[3][6], b.pieces[3][7]);
	printf("  +---+---+---+---+---+---+---+---+\n");
	printf("3 | %c | %c | %c | %c | %c | %c | %c | %c |\n", b.pieces[2][0], b.pieces[2][1], b.pieces[2][2], b.pieces[2][3], b.pieces[2][4], b.pieces[2][5], b.pieces[2][6], b.pieces[2][7]);
	printf("  +---+---+---+---+---+---+---+---+\n");
	printf("2 | %c | %c | %c | %c | %c | %c | %c | %c |\n", b.pieces[1][0], b.pieces[1][1], b.pieces[1][2], b.pieces[1][3], b.pieces[1][4], b.pieces[1][5], b.pieces[1][6], b.pieces[1][7]);
	printf("  +---+---+---+---+---+---+---+---+\n");
	printf("1 | %c | %c | %c | %c | %c | %c | %c | %c |\n", b.pieces[0][0], b.pieces[0][1], b.pieces[0][2], b.pieces[0][3], b.pieces[0][4], b.pieces[0][5], b.pieces[0][6], b.pieces[0][7]);
	printf("  +---+---+---+---+---+---+---+---+\n");
	printf("    A   B   C   D   E   F   G   H\n");
	printf("\n");
}


Board InitGame(Board b){
	b = initBoard();
	//Game(b, op);
	printBoard(b);
	return b;
	
}
